﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace FigureDraw
{
    public class SaveByGDIPlus : FileDevice
    {
        private Graphics g;
        private Pen p;
        private Bitmap b;

        public SaveByGDIPlus(Graphics g, Pen p, Bitmap b)
        {
            this.g = g;
            this.p = p;
            this.b = b;
        }
        public override void drawLine(int x1, int y1, int x2, int y2)
        {
            g.DrawLine(p, x1, y1, x2, y2);
        }

        public override void drawRect(int x, int y, int width, int height)
        {
            x = x - width / 2;
            y = y - height / 2;
            g.DrawRectangle(p, (float)x, (float)y, (float)width, (float)height);
        }

        public override void drawEllipse(int x, int y, int width, int height)
        {
            x = x - width / 2;
            y = y - height / 2;
            g.DrawEllipse(p, (float)x, (float)y, (float)width, (float)height);
        }
        public override void saveToFile(string fileName, string fileExtension)
        {
            switch (fileExtension)
            {
                case "PNG":
                    b.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                    break;
                case "JPEG":
                    b.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;
                case "GIF":
                    b.Save(fileName, System.Drawing.Imaging.ImageFormat.Gif);
                    break;
            }
        }
    }
}
